
<!--车站票款差异确认通知-->
<template>
  <div class="shouPiaoYuanCYQRTZ">
    <basic-container>
      <avue-crud
        ref="shouPiaoYuanCYQRTZ"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="getList"
        @on-load="getList">
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
        </template>

        <template slot-scope="scope" slot="search">
          <el-form-item label="补款人">
            <el-select v-model="searchForm.conductorPersonName" placeholder="请选择" style="width: 150px" clearable filterable>
              <el-option
                v-for="(item,index) in conductorPersonNames"
                :key="index"
                :label="item.nikename"
                :value="item.nikename">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="补款人员工号">
            <el-select v-model="searchForm.conductorJobNo" placeholder="请选择" style="width: 150px" clearable filterable>
              <el-option
                v-for="(item,index) in conductorPersonNames"
                :key="index"
                :label="item.userCode"
                :value="item.userCode">
              </el-option>
            </el-select>
          </el-form-item>
        </template>
        <template slot="search" slot-scope="{row,size}">
            <el-form-item label="差异条件" style="width: 180px" >
              <el-select v-model="searchForm.isDifferenceAmount" placeholder="请选择">
                <el-option label="长款" value="1"></el-option>
                <el-option label="短款" value="2"></el-option>
              </el-select>
            </el-form-item>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small" plain @click.stop="previewOp(scope.row)">预览</el-button>
          <el-button type="text" size="small"
                     v-if="scope.row.appealState==1 && scope.row.sendTime && scope.row.replyPeriod && (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')>=moment())"
                     plain @click.stop="affirm(scope.row)">确认</el-button>
<!--          下发日期加上期限大于当前日期，说明是期限内-->
<!--          <el-button type="text" size="small"-->
<!--                     v-if="scope.row.sendTime && scope.row.replyPeriod && (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')>=moment())"-->
<!--                     plain @click.stop="openApprove(scope.row,1)">期限内审批</el-button>-->
          <el-button type="text" size="small"
                     v-if="(scope.row.appealState ==1 || scope.row.appealState ==4) && scope.row.sendTime && scope.row.replyPeriod && (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')<moment())"
                     plain @click.stop="openApprove(scope.row,2)">超期申诉申请</el-button>
          <!-- <el-button type="text" size="small"
                     v-if="scope.row.appealState==4"
                     plain @click.stop="openApprove(scope.row,1)">超期申诉</el-button> -->
          <el-button type="text" size="small"
                     v-if="scope.row.appealState==2"
                     plain @click.stop="recallAppeal(scope.row)">撤回申诉</el-button>
          <el-button type="text" size="small"
                     v-if="(scope.row.appealState ==1 || scope.row.appealState ==4) && scope.row.sendTime && scope.row.replyPeriod && (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')>=moment())"
                     plain @click.stop="openApprove(scope.row,1)">申诉</el-button>
        </template>
      </avue-crud>
      <approve ref="approve" v-if="dialogVisibleAppealReply"></approve>
      <prev ref="prev" v-if="dialogVisibleprev"></prev>
    </basic-container>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import moment from 'moment';
  import approve from './approve';
  import prev from './prev';

  import {
    clearSelect,
    getgetStationCodes,
    getLineCodes, getSysUserToLS, setSearchFiledsEmpty
  } from "../../../../../../api/subwayRat/commonCheck";
  import {exportDataToExcel} from "../../../../../../api/subwayRat/exportSelf";
  import {getPersonRole} from "../../../../../../api/subwayRat/reportMondify/reportMistakeInfo";
  import {
    getCZ_PK_ZN_Option,
    getSwAuStDiffNoticeList, recallAppealSwAuStDiffNotice,affirmSwAuConductorNotice
  } from "../../../../../../api/stationTiecketManager/xianWngCJXXQR/cheZhanPKCY/cheZhanPKCYQRTZ/zhanNeiRYDLCK";
  export default {
    name: 'zhanNeiRYDLCK',
    components:{
      approve,
      prev
    },
    data() {
      return {
        dialogVisibleAppealReply:false, //申诉回复
        dialogVisibleprev:false,//预览
        option: {},
        listLoading: true,
        lineCodes:[],
        stationCodes:[],
        conductorPersonNames:[],
        selectKeys:[],
        selectKeyVals:[],
        searchForm:{},
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        param:{
          replyPeriod:"",//回复期限
          appealReply:'',//申诉回复
        },
        list : []
      }
    },
    computed: {
      ...mapGetters(['permissions']),
    },
    watch: {
    },
    created() {
      this.option=getCZ_PK_ZN_Option();
    },
    methods: {
      setSearchFiledsEmpty,
      moment,
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.sendState=1;
        this.searchForm.lineCode = this.$store.getters.userInfo.lineCode;
        this.searchForm.stationCode = this.$store.getters.userInfo.stationCode;
        getSwAuStDiffNoticeList(this.searchForm).then((response)=>{
          this.list = response.data.data;
          this.listLoading = false;
          this.page.total=response.data.total;
        });
      },

      openApprove(row,showType){
        this.dialogVisibleAppealReply=true;
        this.$nextTick(()=>{
          this.$refs.approve.dialogVisible=true;
          this.$refs.approve.recallShow(row,showType,this);
        })
      },
      previewOp(row){
        this.dialogVisibleprev=true;
        this.$nextTick(()=>{
          this.$refs.prev.dialogVisible=true;
          this.$refs.prev.recallShow(row,this);
        })
      },
      recallAppeal(row){
        let th=this;
        recallAppealSwAuStDiffNotice({ids:row.id}).then(res=>{
          if(res.data.code==0){
            th.$message.success("操作成功！");
            th.getList();
          }else{
            th.$message.error("操作失败！");
          }
        })
      },
      affirm(row){
        let th=this;
        this.$confirm("是否确认?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          affirmSwAuConductorNotice({id:row.id}).then(res=>{
            th.$message.success("确定成功！");
            th.getList();
          })
          .catch(() => {
              th.$message.error("确定失败！");
          });
        });
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      async exportData(){ // 导出
        let p={};
        this.searchForm.sendState=1;
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        if(this.selectKeys.length>0){
          let newData = JSON.parse(JSON.stringify(this.selectKeys));
          exportDataToExcel(newData,this.option.column,'车站票款差异确认通知-站内人员登录查看');
        }else {
          let res=await getSwAuStDiffNoticeList(p);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'车站票款差异确认通知-站内人员登录查看');
        }
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
        })
      },
      changeStation(v){
        getPersonRole({roleCode:'SPY',stationCode:v}).then((res)=>{
          this.conductorPersonNames=res.data.data;
        });
      },
    },
    mounted() {
      let line_code=this.$store.getters.userInfo.lineCode;
      debugger
      getSysUserToLS({line_code:this.$store.getters.userInfo.lineCode,station_code:this.$store.getters.userInfo.stationCode}).then(res=>{
        this.conductorPersonNames=res.data.data;
      })
    }
  }
</script>
<style lang="scss">
  .huLianWangShouPiaojiDataInput {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
    .avue-form__group{

    }
  }
</style>
